package com.bcu.cn.onlineexamsystem.studentmanage.mapper;

import com.bcu.cn.onlineexamsystem.studentmanage.entity.StudentExam;
import org.apache.ibatis.annotations.*;

@Mapper
public interface StudentExamMapper {
    
    @Insert("INSERT INTO student_exams (student_id, exam_id, start_time, status) " +
            "VALUES (#{studentId}, #{examId}, #{startTime,jdbcType=TIMESTAMP}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "recordId")
    int insert(StudentExam studentExam);
    
    @Update("UPDATE student_exams SET submit_time = #{submitTime}, status = #{status} " +
            "WHERE record_id = #{recordId}")
    int updateSubmitStatus(StudentExam studentExam);
    
    @Update("UPDATE student_exams SET start_time = #{startTime,jdbcType=TIMESTAMP}, status = #{status} WHERE record_id = #{recordId}")
    int updateStartTime(StudentExam studentExam);
    
    @Select("SELECT record_id, student_id, exam_id, start_time AS startTime, submit_time AS submitTime, status, total_score AS totalScore FROM student_exams WHERE student_id = #{studentId} AND exam_id = #{examId}")
    StudentExam findByStudentAndExam(@Param("studentId") String studentId, @Param("examId") Long examId);
} 